home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / bsfengines.jar / com / ibm / bsf / engines / jacl / BSFCommand.class (.txt) next >
Encoding:
Java Class File  |  1999-12-09  |  2.8 KB  |  77 lines

  1. package com.ibm.bsf.engines.jacl;
  2.  
  3. import com.ibm.bsf.BSFEngine;
  4. import com.ibm.bsf.BSFException;
  5. import com.ibm.bsf.BSFManager;
  6. import com.ibm.bsf.util.EngineUtils;
  7. import tcl.lang.Command;
  8. import tcl.lang.Interp;
  9. import tcl.lang.ReflectObject;
  10. import tcl.lang.TclException;
  11. import tcl.lang.TclObject;
  12.  
  13. class BSFCommand implements Command {
  14.    BSFManager mgr;
  15.    BSFEngine jengine;
  16.  
  17.    BSFCommand(BSFManager var1, BSFEngine var2) {
  18.       this.mgr = var1;
  19.       this.jengine = var2;
  20.    }
  21.  
  22.    public void cmdProc(Interp var1, TclObject[] var2) throws TclException {
  23.       if (var2.length < 2) {
  24.          var1.setResult("invalid # of args; usage: bsf lookupBean|registerBean|unregisterBean|addEventListener args");
  25.          throw new TclException(1);
  26.       } else {
  27.          String var3 = var2[1].toString();
  28.          if (var3.equals("lookupBean")) {
  29.             if (var2.length != 3) {
  30.                var1.setResult("invalid # of args; usage: bsf lookupBean name-of-bean");
  31.                throw new TclException(1);
  32.             } else {
  33.                String var8 = var2[2].toString();
  34.                Object var5 = this.mgr.lookupBean(var8);
  35.                if (var5 == null) {
  36.                   var1.setResult("unknown object: " + var8);
  37.                   throw new TclException(1);
  38.                } else {
  39.                   var1.setResult(ReflectObject.newInstance(var1, var5.getClass(), var5));
  40.                }
  41.             }
  42.          } else if (var3.equals("registerBean")) {
  43.             if (var2.length != 4) {
  44.                var1.setResult("invalid # of args; usage: bsf registerBean name-of-bean bean");
  45.                throw new TclException(1);
  46.             } else {
  47.                this.mgr.registerBean(var2[2].toString(), ReflectObject.get(var1, var2[3]));
  48.                var1.setResult("");
  49.             }
  50.          } else if (var3.equals("unregisterBean")) {
  51.             if (var2.length != 3) {
  52.                var1.setResult("invalid # of args; usage: bsf unregisterBean name-of-bean");
  53.                throw new TclException(1);
  54.             } else {
  55.                this.mgr.unregisterBean(var2[2].toString());
  56.                var1.setResult("");
  57.             }
  58.          } else if (var3.equals("addEventListener")) {
  59.             if (var2.length != 6) {
  60.                var1.setResult("invalid # of args; usage: bsf addEventListener object event-set-name filter script-to-run");
  61.                throw new TclException(1);
  62.             } else {
  63.                try {
  64.                   String var4 = var2[4].toString();
  65.                   var4 = var4.equals("") ? null : var4;
  66.                   EngineUtils.addEventListener(ReflectObject.get(var1, var2[2]), var2[3].toString(), var4, this.jengine, this.mgr, "<event-script>", 0, 0, var2[5].toString());
  67.                } catch (BSFException var6) {
  68.                   ((Throwable)var6).printStackTrace();
  69.                   var1.setResult("got BSF exception: " + ((Throwable)var6).getMessage());
  70.                   throw new TclException(1);
  71.                }
  72.             }
  73.          }
  74.       }
  75.    }
  76. }
  77.